package com.qijian.maindata.domain.query;

import com.baomidou.mybatisplus.annotation.TableName;
import com.qijian.common.enums.ApprovalDescriptionEnum;
import com.qijian.common.utils.mybatis.WhereType;
import com.qijian.common.utils.mybatis.WhereTypeEnum;
import lombok.Data;
import lombok.ToString;

import java.util.Date;
import java.util.List;
import java.util.Set;


/**
 * 生产BOM用料单据对象 查询条件类
 *
 * @author qijian
 * @date 2022-05-16
 */

@Data
@ToString
@TableName("main_bom_material")
public class BomMaterialQuery {

    @WhereType(filed = "id")
    private Long id;
    @WhereType(filed = "id", type = WhereTypeEnum.IN)
    private Set<Long> ids;
    @WhereType(filed = "code", type = WhereTypeEnum.LIKE)
    private String checkCode;
    @WhereType(filed = "bom_id")
    private Long bomId;
    @WhereType(filed = "item_name", type = WhereTypeEnum.LIKE)
    private String itemName;
    @WhereType(filed = "grant_id")
    private Long grantId;
    @WhereType(filed = "grant_nick_name", type = WhereTypeEnum.LIKE)
    private String grantNickName;
    @WhereType(filed = "status")
    private String status;
    @WhereType(filed = "approval_by")
    private String approvalBy;
    @WhereType(filed = "approval_time", type = WhereTypeEnum.BETWEEN)
    private Date[] approvalTime;

    @WhereType(filed = "create_time", type = WhereTypeEnum.BETWEEN)
    private String[] createTime;
    @WhereType(filed = "approval_status", type = WhereTypeEnum.NEQ)
    private ApprovalDescriptionEnum approvalStatusNot;

    @WhereType(filed = "approval_status", type = WhereTypeEnum.EQ)
    private ApprovalDescriptionEnum approvalStatusEq;

    @WhereType(ignore = true)
    private String projectNo;

    @WhereType(filed = "project_nos", type = WhereTypeEnum.LIKE)
    private String projectNos;

    @WhereType(ignore = true)
    private String projectId;


    @WhereType(ignore = true)
    private List<String> approvalStatus;

    @WhereType(func = "EXISTS (select 1 from t_flowable_record f  where main_bom_material.id = f.source_id and f.business_key= 'bomMaterial' and f.user_id ={1})")
    private Long u;


    @WhereType(func = "EXISTS (select 1 from t_flowable_record f left join ACT_RU_TASK ru on ru.PROC_INST_ID_=f.process_instance_id inner join ACT_HI_IDENTITYLINK i on i.TASK_ID_=ru.ID_  where main_bom_material.id = f.source_id and f.business_key= 'bomMaterial'  and ( ru.ASSIGNEE_ ={1} or i.USER_ID_ = {1} ))")
    private Long i;


    @WhereType(filed = "approval_status", type = WhereTypeEnum.IN)
    private List<String> approve;

    @WhereType(filed = "create_by", type = WhereTypeEnum.LIKE)
    private String createBy;

    @WhereType(func = "main_bom_material.id \n" +
            "\t\tIN (\n" +
            "\t\tSELECT\n" +
            "\t\t\tDISTINCT a.Main_ID\n" +
            "\t\tFROM\n" +
            "\t\t\tmain_bom_material_project a\n" +
            "\t\t\tINNER JOIN main_project b ON a.project_id = b.project_id \n" +
            "\t\t\tAND b.is_del = 0\n" +
            "\t\t\tINNER JOIN main_bom c ON c.bom_id = b.bom_id \n" +
            "\t\t\tAND c.is_del = 0 \n" +
            "\t\t\tWHERE c.bom_id = {1})")
    private Long bomIdNew;
}
